using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SMWJamecl.BusinessEntities;

namespace SMWJamecl.Repository.Mapping
{
    public class DetalleAlquilerMap : EntityTypeConfiguration<DetalleAlquiler>
    {
        public DetalleAlquilerMap()
        {
            // Primary Key
            this.HasKey(t => new { t.AlquilerId, t.Placa });

            // Properties
            this.Property(t => t.AlquilerId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Placa)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(7);

            // Table & Column Mappings
            this.ToTable("DetalleAlquiler");
            this.Property(t => t.AlquilerId).HasColumnName("AlquilerId");
            this.Property(t => t.Placa).HasColumnName("Placa");
            this.Property(t => t.Chofer).HasColumnName("Chofer");
            this.Property(t => t.Costo_diarioChofer).HasColumnName("Costo_diarioChofer");
            this.Property(t => t.Costo_diarioVehiculo).HasColumnName("Costo_diarioVehiculo");

            // Relationships
            this.HasRequired(t => t.Aquiler)
                .WithMany(t => t.DetalleAlquilers)
                .HasForeignKey(d => d.AlquilerId);
            this.HasRequired(t => t.Vehiculo)
                .WithMany(t => t.DetalleAlquilers)
                .HasForeignKey(d => d.Placa);

        }
    }
}
